#include <iostream>
#include <cstdio>

using namespace std;

const int MAXN = 1000, MAXM = 1000000;
int n, m;
int first[MAXN];
int next[MAXM];
int u[MAXM], v[MAXM], w[MAXM];

void read_graph() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) first[i] = -1;
    for (int e = 0; e < m; ++e) {
        cin >> u[e] >> v[e] >> w[e];
        next[e] = first[u[e]];
        first[u[e]] = e;
    }
}

int main() {
    freopen("adj_list.in", "r", stdin);
    read_graph();
    for (int i = 0; i < n; ++i) {
        cout << "Node " << i << ": ";
        for (int e = first[i]; e != -1; e = next[e])
            cout << e << ' ';
        cout << endl;
    }
}

